Strict

Class Vector2d
	public
	Field x:float
	Field y:float

	Method New()	
		self.setX(0)
		self.setY(0)
	End

	Method New(x:float, y:float)	
		self.setX(x)
		self.setY(y)
	End

	Method  setX:void(x:float) 
		self.x = x
	End
	
	Method getX:float() 
		return x
	End

	Method  setY:void(y:float) 
		self.y = y
	End

	Method getY:float() 
		return y
	End

	Method set:void(x:float , y:float)	
		self.setX(x)
		self.setY(y)
	End


	Method dot:float(v2:Vector2d)	
		Local result:float = 0.0
		result = self.getX() * v2.getX() + self.getY() * v2.getY()
		return result
	End

	Method getLength:float()	
		return float(Sqrt(getX()*getX() + getY()*getY()))
	End

	Method getDistance:float(v2:Vector2d)	
		return float( Sqrt((v2.getX() - getX()) * (v2.getX() - getX()) + (v2.getY() - getY()) * (v2.getY() - getY())))
	End


	Method add:Vector2d(v2:Vector2d, result:Vector2d)	
		'Local result:Vector2d = new Vector2d()
		result.setX(getX() + v2.getX())
		result.setY(getY() + v2.getY())
		return result
	End

	Method subtract:Vector2d(v2:Vector2d, result:Vector2d)	
		'Local result:Vector2d = new Vector2d()
		result.setX(self.getX() - v2.getX())
		result.setY(self.getY() - v2.getY())
		return result
	End

	Method multiply:Vector2d (scaleFactor:float, result:Vector2d)	
		'Local result:Vector2d = new Vector2d()
		result.setX(self.getX() * scaleFactor)
		result.setY(self.getY() * scaleFactor)
		return result
	End

	Method  normalize:Vector2d()
		Local len:float = getLength()
		if (len <> 0.0)
			self.setX(self.getX() / len)
			self.setY(self.getY() / len)		
		else		
			self.setX(0.0)
			self.setY(0.0)
		Endif

		return self
	End

	Method toString:String()	
		return "X: " + getX() + " Y: " + getY()
	End
End
